using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DAO;
using DTO;
namespace BUS
{
    public static class hocsinhBUS
    {
        #region le quan dai
        public static bool themhocsinh(hocsinhDTO hocsinhDTO)
        {
            //kiem tra ma co ton tai hay khong
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhsachhocsinh();
            for(int i=0;i<dt.Rows.Count;i++)
            {
                dr=dt.Rows[i];
                if (dr["mahs"].ToString().Equals(hocsinhDTO.Mahs))
                    return false;
            }
                return hocsinhDAO.themhocsinh(hocsinhDTO);
            
        }
        //them diem
        public static bool themdiem(ketquaDTO ketquadto)
        {
            //kiem tra mon da co diem 
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhSachKetQua();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];
                if (dr["mamh"].ToString().Equals(ketquadto.Mamh) && dr["mahk"].ToString().Equals(ketquadto.Mahk) && dr["mahs"].ToString().Equals(ketquadto.Mahs) && dr["malop"].ToString().Equals(ketquadto.Malop))
                    return false;
            }
            return hocsinhDAO.themdiem(ketquadto);

        }
        //sua diem
        public static bool suadiem(ketquaDTO ketquadto)
        {
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhsachketqua(ketquadto);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];
                //kiem tra neu ma trung khop thi cap nhat khong tra ve false
                if (dr[0].ToString().Equals(ketquadto.Mahs))
                    return hocsinhDAO.suadiem(ketquadto);
                return true;
            }
            return false;
        }
        //tim kiem hoc sinh
        public static bool timhocsinhma(hocsinhDTO hocsinhDTO)
        {
            //kiem tra ma co ton tai hay khong
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhsachhocsinh();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];
                if (dr["mahs"].ToString().Equals(hocsinhDTO.Mahs))
                    return true;
            }
            return false;
        }
        //tim kiem theo ten hoc sinh
        public static bool timhocsinhtheoten(hocsinhDTO hocsinhDTO)
        {
            //kiem tra ma co ton tai hay khong
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhsachhocsinh();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];
                if (dr["hoten"].ToString().Equals(hocsinhDTO.Hoten))
                    return true;
            }
            return false;
        }
        
        public static bool capnhathocsinh(hocsinhDTO hocsinhDTO)
        {
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhsachhocsinh();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];
                //kiem tra neu ma trung khop thi cap nhat khong tra ve false
                if (dr["mahs"].ToString().Equals(hocsinhDTO.Mahs))
                    return hocsinhDAO.capnhathocsinh(hocsinhDTO);
            }
            return false;
        }

        //xoa hoc sinh
        public static bool xoahocsinh(hocsinhDTO hocsinhDTO)
        {
            DataRow dr;
            DataTable dt;
            dt = hocsinhDAO.danhsachhocsinh();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];
                if (dr["mahs"].ToString().Equals(hocsinhDTO.Mahs))
                    return hocsinhDAO.xoahocsinh(hocsinhDTO);
            }
            return false;
        }
        //kiem tra dang nhap he thong cua adimin
        public static bool dangnhapadmin( AdminDTO addto)
        {
           
            DataTable dtadmin;
            
            dtadmin = hocsinhDAO.danhsachadmin();
            foreach (DataRow dradmin in dtadmin.Rows)
            {
                if (dradmin["tendn"].ToString() == addto.TenDN && dradmin["matkhau"].ToString() == addto.MatKhau)
                    return true;
            }
            return false;

        }
        //kiem tra dang nhap he thong cua giaovien
        public static bool dangnhapgiaovien(GiaoVienDTO gvdto)
        {
            DataTable dtgv;

            dtgv = hocsinhDAO.danhsachgiaovien();
            foreach (DataRow drgv in dtgv.Rows)
            {
                if (drgv["magv"].ToString() ==gvdto.MaGV  && drgv["tengv"].ToString() == gvdto.TenGV)
                    return true;
            }
            return false;

        }
        //danh sach lop
        public static DataTable danhsachlop()
        {
            return hocsinhDAO.danhsachlop();
        }
        //danh sach mon hoc
        public static DataTable danhsachmonhoc()
        {
            return hocsinhDAO.danhsachmonhoc();
        }
        //danh sach hanh kiem
        public static DataTable danhsachhanhkiem()
        {
            return hocsinhDAO.danhsachhanhkiem();
        }
        //danh sach hoc sinh
        public static DataTable danhsachhocsinh()
        {
            return hocsinhDAO.danhsachhocsinh();
        }
        //danh sach hoc sinh con hoc
        public static DataTable danhsachhocsinhcon()
        {
            return hocsinhDAO.danhsachhocsinhcon();
        }
        //danh sach hoc ki
        public static DataTable danhsachhocki()
        {
            return hocsinhDAO.danhsachhocki();
        }
        //danh sach khoi
        public static DataTable danhsachkhoi()
        {
            return hocsinhDAO.danhsachkhoi();
        }
        //danh sach lop theo khoi
        public static DataTable danhsachloptheokhoi(KhoiDTO khoidto)
        {
            return hocsinhDAO.danhsachloptheokhoi(khoidto);
        }
        //danh sach nhap diem
        public static DataTable danhsachnhapdiem(ketquaDTO ketquadto)
        {
            return hocsinhDAO.danhsachnhapdiem(ketquadto);
        }
        //danh sach xem ket qua
        public static DataTable danhsachketqua(ketquaDTO ketquadto)
        {
            return hocsinhDAO.danhsachketqua(ketquadto);
        }
        #endregion

        #region Nguyen Thanh Duy

        public static DataTable danhSachHocLuc()
        {
            return hocsinhDAO.danhSachHocLuc();
        }
        public static DataTable danhSachKetQua()
        {
            return hocsinhDAO.danhSachKetQua();
        }
        public static DataTable danhSachKhoi()
        {
            return hocsinhDAO.danhSachKhoi();
        }
        public static DataTable danhSachNamHoc()
        {
            return hocsinhDAO.danhSachNamHoc();
        }

        #endregion
    }
}
